package controller

import (
	"fmt"
	"music/util/request"
	"strconv"
)

//获取歌曲链接地址
func SongUrl(query map[string]interface{}) map[string]interface{} {
	data := map[string]interface{}{}
	if val, err := strconv.Atoi(fmt.Sprintf("%v", query["id"])); err == nil {
		data["ids"] = fmt.Sprintf("[%v]", val)
	}
	if val, ok := query["br"]; ok && val != "" {
		data["br"] = val
	} else {
		data["br"] = 999000
	}
	// options := map[string]interface{}{
	// 	"crypto": "api",
	// 	"cookie": query["cookie"],
	// 	"proxy":  query["proxy"],
	// }
	// fmt.Printf("%v", data)
	// result := request.CreateRequest(
	// 	"GET", "https://interface3.music.163.com/api/song/enhance/player/url",
	// 	data,
	// 	options)
	// result := request.GetRequest("http://api.music.canace.cn/v1/kuwo/playlist/info", data)
	result := request.GetRequest("https://interface3.music.163.com/api/song/enhance/player/url", data)
	return result

}

//获取歌曲详细信息
func SongDetail(query map[string]interface{}) map[string]interface{} {
	data := map[string]interface{}{}
	if val, err := strconv.Atoi(fmt.Sprintf("%v", query["id"])); err == nil {
		data["c"] = fmt.Sprintf("[{\"id\":%v}]", val)
	}
	result := request.GetRequest("https://music.163.com/api/v3/song/detail", data)
	return result
}

//获取歌曲歌词
func SongLyric(query map[string]interface{}) map[string]interface{} {
	data := map[string]interface{}{}
	if val, ok := query["id"]; ok && val != "" {
		data["id"] = val
	} else {
		data["id"] = 33894312
	}
	data["lv"] = -1
	data["kv"] = -1
	data["tv"] = -1
	result := request.GetRequest("https://music.163.com/api/song/lyric", data)
	return result
}
